import Pagination from "@/components/pagination";
import {
  Message
} from "element-ui";
const easydate = require("@/untils/easydate");
export default {
  components: {
    Pagination
  },
  props: ["activeName"],
  data() {
    return {
      paginationNum:1,
      loading:false,
      tingsTip:'',
      thingsText:'',
      turnPageObj: {},
      fileListMenus: [], // 默认文件
      teaSelectList:[],
      smallLoading: false, // 默认文件上传过度
      checkApply: false,
      searchLoading: false,
      total: 10,
      checkStatus: true,
      agree: false,
      disAgree: false,
      infoTitle: '',
      planObj: {
        "type" : "2",
        "page":1, 
        "pageSize":10,
        "workType":"",
        "deptName": "",
      },
      planUpload: {
        type:'2',
        "workType": "",
        "deptName": '',
        workDescribe :'',
        "multipartFile": ''
      },
      // 微课程校验
      planRules: {
        workType: [{
          required: true,
          message: "请输入文件类别",
          trigger: "blur"
        }],
        workDescribe: [{
          required: true,
          message: "请输入名称",
          trigger: "blur"
        }]
      },
      tableData: [],
      deptName: "",
      status: "",
    };
  },
  mounted() {
    let that = this;
    let {
      planObj
    } = that;
    that.getApproval(planObj);
  },
  methods: {
    handleSelectionChange(e) {
      let that = this;
      let idArr = [];
      e.map(function (item) {
        idArr.push(item.id);
      });
      that.deletIds = idArr;
    },
    pageNum(prop) {
      this.searchList(prop, 10);
      this.paginationNum = prop;
    },
    pageSizeNum(prop) {
      this.searchList(1, prop);
    },
    limitNums() {
      Message({
        message: "只能上传一个文件",
        type: "warning",
        duration: 2000
      });
    },
    // 视频文件删除
    limitRemoves(flie) {
      this.$refs.uploads.clearFiles();
      this.fileListMenus = [];
      this.planUpload.multipartFile = null;
    },
    // 微课程文件
    addAttachments(file, fileList) {
      this.planUpload.multipartFile = file.raw;
      this.fileListMenus = fileList;
    },
    handleClose(done) {
      this.$nextTick(() => {
        this.$refs.planForm.resetFields();
      });
      this.planUpload.multipartFile = '';
      this.fileListMenus = [];
      done();
    },
    diloagClose(){
      this.$nextTick(() => {
        this.$refs.planForm.resetFields();
      });
      this.planUpload.multipartFile = '';
      this.fileListMenus = [];
    },
    searchList(pageNum, pageSize) {
      let {
        planObj
      } = this;
      planObj.page = pageNum;
      planObj.pageSize = pageSize;
      this.searchLoading = true;
      this.getApproval(planObj);
      this.turnPageObj = planObj;
    },
    addThings(){
      this.checkApply = true;
      this.thingsText = '新增外购外派';
      this.tingsTip = '录入信息';
    },
    querySearch(queryString) {
      let params = {
        name: queryString
      }
      let that = this;
      that.$get('qryLikeDeptMessage', params).then(res => {
        if (res.success) {
          this.teaSelectList = res.data;
          this.loading = false;
        }else{
          this.loading = false;
        }
      })
    },
    handleSelect(val) {
      // this.teaName = val.username;
      this.planUpload.deptName = val;
    },
    deleteClick(row) {
      this.$confirm("此操作将删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let { paginationNum } = this;
        let params = {
          id: row.id
        }
        this.$get('deleteByHandleAffairsId', params).then(res => {
          if (res.success) {
            Message({
              message: "操作成功",
              type: "success",
              duration: 2000
            });
            this.searchList(paginationNum, 10);
          }
        })
      });
    },
    applyClick(row, status) {
      let that = this;
      console.log(row);
      let params = {
        id: row.id
      };
      that.$get("getApprovalInfo", params, true).then(res => {
        if (res.success) {
          that.checkApply = true;
          if (status) {
            that.checkStatus = false;
          } else {
            that.checkStatus = true;
          }
          for (var key in res.data) {
            if (key == "hiredDate") {
              res.data.hiredDate = res.data.hiredDate.split(' ')[0];
            }
            if (key == "detentionTime") {
              res.data.detentionTime = res.data.detentionTime + '年';
            }
          }
          that.getApprovalInfo = res.data;
        }
      });
    },
    apply() {
      let {
        planUpload,paginationNum
      } = this;
      let formdata = new FormData();
      for (var key in planUpload) {
        formdata.append(key, planUpload[key]);
      }
      let config = {
        header: {
          'Content-Type': 'mutipart/form-data'
        }
      }
      // if(!planUpload.deptName){
      //   Message({
      //     message: "请选择部门",
      //     type: "warning",
      //     duration: 2000
      //   });
      //   return
      // }
      if(!planUpload.multipartFile){
        Message({
          message: "请上传文件",
          type: "warning",
          duration: 2000
        });
        return
      }
      this.$refs.planForm.validate(valid => {
        if (valid) {
          this.smallLoading = true;
          this.disAgree = true;
          this.agree = true;
          this.$http.post('/handleAffairs/insertHandleAffairs', formdata, config).then(res => {
            if (res.data.success) {
              Message({
                message: "操作成功",
                type: "success",
                duration: 2000
              });
              this.checkApply = false;
              this.smallLoading = false;
              this.disAgree = false;
              this.agree = false;
              this.searchList(paginationNum, 10);
            }else{
              this.smallLoading = false;
              this.disAgree = false;
              this.agree = false;
            }
          })
        }
      })
    },
    getApproval(params) {
      this.$post('qryHandleAffairsList', params).then(res => {
        if (res.success) {
          this.tableData = res.data.handleAffairs;
          this.total = res.data.totals;
          this.searchLoading = false;
        }
      })
    }
  }
};
